package Analysis;

import java.util.ArrayList;

import Definitions.NodeClass;
import Global.ConstantVariable;
import Global.GlobalClass;
import LocalClassifier.LocalClassifierInterface;
import Sampling.SamplingAbstractClass;

public abstract class CorrelationAbstractClass {

	public static double[] CalculateCorrelationForGivenSet(LocalClassifierInterface lc,ArrayList<NodeClass> nodeList, int level, int stage, SamplingAbstractClass currentSampling)
	{
		GlobalClass global = currentSampling.getGlobal();
	
		int numberOfSample = nodeList.size();
		int classSize = global.classList.size();
		double[][] xMatrix = new double[numberOfSample][classSize];
		double[][] yMatrix = new double[numberOfSample][classSize];
		
		for(int i= 0; i<numberOfSample; i++)
		{
			xMatrix[i] = createNeighborsAccuracy(lc, nodeList.get(i), level, stage, currentSampling);

			// TODO (KADRIYEB ): Soft ?  
			yMatrix[i] = lc.evaluate(nodeList.get(i), ConstantVariable.Sampling_Constants.NODE_IS_IN_TEST_SET_FOR_THE_FOLD, "soft");  
		}
		
		return GetCorrelation(xMatrix, yMatrix);
	}
	
	public static double[] createNeighborsAccuracy(LocalClassifierInterface lc,NodeClass u, int level ,int stage, SamplingAbstractClass currentSampling)
	{
		GlobalClass global = currentSampling.getGlobal();

		ArrayList<NodeClass> neigbors = currentSampling.findNeighbours(u, stage, 0, level);
		
		double sum [] = new double[global.classList.size()];
		
		for (int i=0; i<sum.length ; i++)
		{
			sum[i]=0;
		}
		
		double temp[] = new double[global.classList.size()];
		
		for(NodeClass v : neigbors)
		{
			
			temp= lc.evaluate(v, ConstantVariable.Sampling_Constants.NODE_IS_IN_TEST_SET_FOR_THE_FOLD, " ");
			
			for(int i= 0; i<sum.length; i++)
			{
				sum[i] += temp[i]; 
			}
		}
		for (double f : sum)
		{
			f= f/ (double)(sum.length);
		}
		
		return sum;
	}

	public static double[] GetCorrelation (double xMatrix[][], double yMatrix[][])
	{
		return null;
	}
	
}
